package com.hongye.broker.service.impl;

import com.hongye.broker.mapper.BrokerMapper;
import com.hongye.broker.mapper.StoreyMapper;
import com.hongye.broker.service.StoreyService;
import com.hongye.common.entity.BrokerEntity;
import com.hongye.common.entity.StoreyEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.Date;
import java.util.List;

@Service
public class StoreyServiceImpl implements StoreyService {

    @Autowired
    private StoreyMapper storeyMapper;

    @Autowired
    private BrokerMapper brokerMapper;
    @Override
    public List<StoreyEntity> findAll() {
        List<StoreyEntity> list = storeyMapper.findAll();
        return list;
    }

    @Override
    public void dele(Integer id) {
        storeyMapper.dele(id);
    }

    @Override
    public void save(StoreyEntity storeyEntity) {
        Long brokerId = storeyEntity.getBrokerId();
        BrokerEntity entity = brokerMapper.findOne(brokerId);
        storeyEntity.setBrokerName(entity.getBrokerName());
        storeyEntity.setBrokerImage(entity.getImage());
        storeyEntity.setStoreyTime(new Date());
        storeyMapper.save(storeyEntity);
    }
}
